$(document).ready(function(){  
	$("#province_select").change(function(){
	    $.ajax({
	      url: '/cities/ajax_cities',
	      type: 'POST',
	      dataType: 'html',
	      data: {province_id:$(this).val()},
	      complete: function(xhr, textStatus) {
	        //called when complete
	      },
	      success: function(data, textStatus, xhr) {
	        //called when successful
	          	$("#city_select").html(data);
	          	$("#city_select").removeAttr('disabled');
	      },
	      error: function(xhr, textStatus, errorThrown) {
	        alert(errorThrown);
	      }
	    });
	});
	$('#city_select').change(function() {
	    $('#JobCityId').val($(this).val());
	});
	
});


	function addWord(form){
		var datas = $(form).serialize();
		$(form).children().attr('disabled','disabled');
		$.ajax({
		  url: '/words/add',
		  type: 'POST',
		  dataType: 'json',
		  data: datas,
		  complete: function(xhr, textStatus) {
		    //called when complete
		  },
		  success: function(data, textStatus, xhr) {
		    //called when successful
				$(form).children().removeAttr('disabled');
				var first_child = $("#word-list > :first");
				if (first_child) {
				   first_child.before("<li>"+data.word+"["+data.language+"] : "+data.description+"</li>");
				}else{
				    $("#word-list").add("<li>"+data.word+"["+data.language+"] : "+data.description+"</li>");
				};
				form.reset();

		  },
		  error: function(xhr, textStatus, errorThrown) {
		    //called when there is an error
		    alert(errorThrown);
    		$(form).children().removeAttr('disabled');

		  }
		});	
   	 	return false;
	}
	
	function addAwnser (form) {
		var datas = $(form).serialize();
		$(form).children().attr('disabled','disabled');
		$.ajax({
		  url: '/awnsers/add',
		  type: 'POST',
		  dataType: 'json',
		  data: datas,
		  complete: function(xhr, textStatus) {
		    //called when complete
		  },
		  success: function(data, textStatus, xhr) {
		    //called when successful
				$(form).children().removeAttr('disabled');
				var first_child = $("#word-list > :first");
				if (first_child) {
				   first_child.before("<li>"+data.word+"["+data.language+"] : "+data.description+"</li>");
				}else{
				    $("#word-list").add("<li>"+data.word+"["+data.language+"] : "+data.description+"</li>");
				};
				form.reset();

		  },
		  error: function(xhr, textStatus, errorThrown) {
		    //called when there is an error
		    alert(errorThrown);
    		$(form).children().removeAttr('disabled');

		  }
		});	
   	 	return false;		
	}
	function addUserLan (form) {
		var datas = $(form).serialize();
		$.ajax({
		  url: '/user_languages/ajax_add',
		  type: 'POST',
		  dataType: 'html',
		  data:  datas,
		  complete: function(xhr, textStatus) {
		    //called when complete
		  },
		  success: function(data, textStatus, xhr) {
		    //called when successful
		    $('#user-lan-list').append(data);
		  },
		  error: function(xhr, textStatus, errorThrown) {
		    //called when there is an error
		  }
		});
		return false;
	}
/*	function addGuest (form) {
		var datas = $(form).serialize();
		$(form).children().attr('disabled','disabled');
		$.ajax({
		  url: '/guest/add',
		  type: 'POST',
		  dataType: 'json',
		  data: datas,
		  complete: function(xhr, textStatus) {
		    //called when complete
		  },
		  success: function(data, textStatus, xhr) {
		    //called when successful
				$(form).children().removeAttr('disabled');
				$("#guest-list :first-child").before("<li>"+data.word+"["+data.language+"] : "+data.description+"</li>");
				 

		  },
		  error: function(xhr, textStatus, errorThrown) {
		    //called when there is an error
		    alert(errorThrown);
    		$(form).children().removeAttr('disabled');

		  }
		});	
   	 	return false;
	}
*/